// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
signed main()
{
	int t=1;
//	cin>>t;
	while(t--)
	{
		int n,mx=0;
		cin>>n;
		vector<int> v(n+1);
		unordered_map<int,int> hash;
		bool f=0,f2=0;
		for(int i=1;i<=n;i++)
		{
			cin>>v[i];
			hash[v[i]]=1;
			mx=max(mx,v[i]);
			if(!f&&v[i]==0)f=1;
			if(!f2&&v[i]!=0)f2=1;
		}
		if(!f)
		{
			cout<<-1;
			return 0;
		}
		if(!f2)
		{
			cout<<0;
			return 0;
		}
		int mex,cnt=0;
		while(mx>0)
		{
			//if(mx<INT_MAX)(int)mx=mx;
			bool f1=0;
			for(int i=0;i<=mx+1;i++)
			{
				if(!hash[i]&&!f1)
				{
					mex=i;
					f1=1;
				}
				else 
				{
					if(hash[i]&&f1)hash[i-mex]=1;
					if(i!=0)hash[i]=0;
				}
			}
			//mx-=mex;
			mx=max(0ull,mx-mex);
			cnt++;
		}
		cout<<cnt;
	}
	return 0;
}
